﻿using System.Linq;
using System.Collections.Generic;
using Domain.Dummies.Dtos;
using Domain.Dummies.Dtos.Collections;
using AutoMapper;

namespace Domain.Dummies
{
    public class Database
    {
        private static Database pMe = null;

        private readonly ICollection<StudentDto> StudentsList = new List<StudentDto>();
        private readonly ICollection<TeacherDto> TeachersList = new List<TeacherDto>();
        private readonly ICollection<GroupDto> GroupsList = new List<GroupDto>();
        private readonly ICollection<ExamDto> ExamsList = new List<ExamDto>();
        private readonly ICollection<SubjectDto> SubjectList = new List<SubjectDto>();
        private readonly ICollection<BookDto> BooksList = new List<BookDto>();
        private readonly ICollection<BooksWithPersonListDto> WhoGetBookList = new List<BooksWithPersonListDto>();

        public ICollection<StudentDto> Students { get { return StudentsList; } }
        public ICollection<TeacherDto> Teachers { get { return TeachersList; } }
        public ICollection<GroupDto> Groups { get { return GroupsList; } }
        public ICollection<ExamDto> Exams { get { return ExamsList; } }
        public ICollection<SubjectDto> Subjects { get { return SubjectList; } }
        public ICollection<BookDto> Books { get { return BooksList; } }
        public ICollection<BooksWithPersonListDto> WhoGetBook { get { return WhoGetBookList; } }

        
        public static string DimaPhilimonovGuidString    = "dddddddd-dddd-dddd-dddd-dddddddddddd";
        public static string AlexAgrutinGuidString       = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
        public static string TimurRachmatilaevGuidString = "efca0fca-efef-efef-efef-efefefefefef";

        public static string MPSGUIDSTRING               = "aaaaaeee-aaae-aaaa-aaaa-aaaaeeeeefff";
        public static string OSGUIDSTIRNG                = "22222222-2222-2222-2222-222222222222";
        public static string CSHARPGUIDSTRING            = "54354354-3543-5435-4354-354354354354";
        public static string VinnikovGuidString          = "00000111-0000-0000-0000-111111111111";
        public static string KorchomkinGuidString        = "00000101-3333-0101-3333-010101000001";
        

        public static string PS572GuidString = "57257257-2572-5725-7257-257257257257";
        public static string PS574GuidString = "57457457-4574-5745-7457-457457457457";


        public static Database get()
        {
            if (pMe == null)
                pMe = new Database();

            return pMe;
        }

        private Database()
        {
            //---------------------------------------------------------------------
            
            //Students, exits by default
            Students.Add(
                new StudentDto()
                {
                    Id = new System.Guid(DimaPhilimonovGuidString),
                    Name = "Dima Alex Philimonov"
                });
            Students.Add(
                new StudentDto()
                {
                    Id = new System.Guid(AlexAgrutinGuidString),
                    Name = "Alexander Vlad Argutin"
                });
            Students.Add(
                new StudentDto()
                {
                    Id = new System.Guid(TimurRachmatilaevGuidString),
                    Name = "Timur H Rachmatilaev"
                });
            //---------------------------------------------------------------------

            //Teachers, exists by default
            Teachers.Add(
                new TeacherDto()
                {
                    Id = new System.Guid(VinnikovGuidString),
                    Name = "Винников Борис Васильевич"
                });
            Teachers.Add(
                new TeacherDto()
                {
                    Id = new System.Guid(KorchomkinGuidString),
                    Name = "Корчемкин Юрий Валерьевич"
                });
            //---------------------------------------------------------------------
            
            //Groups, exists by default
            Groups.Add(
                new  GroupDto()
                {
                    Id = new System.Guid(PS572GuidString),
                    Name = "ПС-572",
                    StudentsGuids = new[]
                    {
                        new System.Guid(DimaPhilimonovGuidString),
                        new System.Guid(AlexAgrutinGuidString)
                    }
                });
            Groups.Add(
                new GroupDto()
                {
                    Id = new System.Guid(PS574GuidString),
                    Name = "ПС-574",
                    StudentsGuids = new[]
                    {
                        new System.Guid(TimurRachmatilaevGuidString)
                    }
                });
            //---------------------------------------------------------------------
            
            //Subjects, exists by default
            Subjects.Add(
                new SubjectDto()
                {
                    Id = new System.Guid(OSGUIDSTIRNG),
                    Name = "Операционные системы",
                    Hours = 140
                });
            Subjects.Add(
                new SubjectDto()
                {
                    Id = new System.Guid(CSHARPGUIDSTRING),
                    Name = "Программирование в среде .NET 4.0",
                    Hours = 120
                });
            Subjects.Add(
                new SubjectDto()
                {
                    Id = new System.Guid(MPSGUIDSTRING),
                    Name = "Микропроцессорные системы",
                    Hours = 120
                });
            //---------------------------------------------------------------------

            //Books, exists by default
            Books.Add(
                new BookDto()
                {
                    Id = System.Guid.NewGuid(),
                    Author = "Л. Н. Толстой",
                    Title = "Война и мир",
                    PagesCount = 1173,
                    Year = 1856
                });
            Books.Add(
                new BookDto()
                {
                    Id = System.Guid.NewGuid(),
                    Author = "Ф. М. Достоевский",
                    Title = "Идиот",
                    PagesCount = 400,
                    Year = 1868
                });
            Books.Add(
                new BookDto()
                {
                    Id = System.Guid.NewGuid(),
                    Author = "М. Горький",
                    Title = "Мои университеты",
                    PagesCount = 254,
                    Year = 1923
                });
            Books.Add(
                new BookDto()
                {
                    Id = System.Guid.NewGuid(),
                    Author = "Э. Таненбаум",
                    Title = "Компьютерные сети",
                    PagesCount = 991,
                    Year = 2003
                });
            //---------------------------------------------------------------------

            //WhoGetBook = relations by defalult;
            Mapper.CreateMap<TeacherDto, PersonDto>();
            Mapper.CreateMap<StudentDto, PersonDto>();

            WhoGetBook.Add(
                new BooksWithPersonListDto()
                {
                    HolderPerson = Mapper.Map<TeacherDto, PersonDto>(
                        Teachers.Where(person => person.Id.ToString().Equals(KorchomkinGuidString)).First()
                                                                ),
                    Books = Books.Where(ibook => ibook.Year == 2003 || ibook.Year == 1923).ToList()
                });
            WhoGetBook.Add(
                new BooksWithPersonListDto()
                {
                    HolderPerson = Mapper.Map<TeacherDto, PersonDto>(
                        Teachers.Where(person => person.Id.ToString().Equals(VinnikovGuidString)).First()
                        ),
                    Books = Books.Where(ibook => ibook.PagesCount > 1000).ToList()
                });
            WhoGetBook.Add(
                new BooksWithPersonListDto()
                {
                    HolderPerson = Mapper.Map<StudentDto, PersonDto>(
                        Students.Where(person => person.Id.ToString().Equals(AlexAgrutinGuidString)).First()
                        ),
                    Books = Books.Where(ibook => ibook.PagesCount == 254).ToList()
                });
                        
        }        

        public static readonly TeacherWeekFullDataScheduleDto KorchomkinWeekFullDataSchedule = new TeacherWeekFullDataScheduleDto()
        {
            RequestedWeek = System.DateTime.Parse("10.01.2011"),
            Teacher = new TeacherDto()
            {
                Id = new System.Guid(KorchomkinGuidString),
                Name = "Корчемкин Юрий Валерьевич"
            },

            Days = new []
            {
                new TeacherDayItemWSScheduleDto()
                {
                    WeekDay = System.DayOfWeek.Monday,
                    Lines = new []
                    {
                        new TeacherLineWSScheduleDto()
                        {
                            Time = System.DateTime.Parse("01.01.2000 08:00"),
                            Auditory = "801/3б",
                            Subject = new SubjectDto()
                            {
                                Id = new System.Guid(OSGUIDSTIRNG),
                                Name = "Операционные системы",
                                Hours = 140
                            },
                            GroupsGuids = new []
                            {
                                new System.Guid(PS572GuidString)
                            },
                            ExtraInformation = "May be some practice"
                        },
                        new TeacherLineWSScheduleDto()
                        {
                            Time = System.DateTime.Parse("01.01.2000 09:45"),
                            Auditory = "801/3б",
                            Subject = new SubjectDto()
                            {
                                Id = new System.Guid(OSGUIDSTIRNG),
                                Name = "Операционные системы",
                                Hours = 140
                            },
                            GroupsGuids = new []
                            {
                                new System.Guid(PS574GuidString)
                            },
                            ExtraInformation = "May be some practice"
                        }
                    }
                },
                new TeacherDayItemWSScheduleDto()
                {
                    WeekDay = System.DayOfWeek.Tuesday,
                    Lines = new []
                    {
                        new TeacherLineWSScheduleDto()
                        {
                            Time = System.DateTime.Parse("01.01.2000 13:35"),
                            Auditory = "802/3б",
                            Subject = new SubjectDto()
                            {
                                Id = new System.Guid(OSGUIDSTIRNG),
                                Name = "Операционные системы",
                                Hours = 140
                            },
                            GroupsGuids = new []
                            {
                                new System.Guid(PS572GuidString)
                            },
                            ExtraInformation = "May be some practice"
                        },
                        new TeacherLineWSScheduleDto()
                        {
                            Time = System.DateTime.Parse("01.01.2000 15:20"),
                            Auditory = "802/3б",
                            Subject = new SubjectDto()
                            {
                                Id = new System.Guid(OSGUIDSTIRNG),
                                Name = "Операционные системы",
                                Hours = 140
                            },
                            GroupsGuids = new []
                            {
                                new System.Guid(PS574GuidString)
                            },
                            ExtraInformation = "May be some practice"
                        }
                    }
                },
                new TeacherDayItemWSScheduleDto()
                {
                    WeekDay = System.DayOfWeek.Wednesday,
                    Lines = new []
                    {
                        new TeacherLineWSScheduleDto()
                        {
                            Time = System.DateTime.Parse("01.01.2000 9:45"),
                            Auditory = "240/3б",
                            Subject = new SubjectDto()
                            {
                                Id = new System.Guid(OSGUIDSTIRNG),
                                Name = "Операционные системы",
                                Hours = 140
                            },
                            GroupsGuids = new []
                            {
                                new System.Guid(PS572GuidString),
                                new System.Guid(PS574GuidString)
                            },
                            ExtraInformation = "Lecture only"
                        },
                        new TeacherLineWSScheduleDto()
                        {
                            Time = System.DateTime.Parse("01.01.2000 11:30"),
                            Auditory = "240/3б",
                            Subject = new SubjectDto()
                            {
                                Id = new System.Guid(OSGUIDSTIRNG),
                                Name = "Операционные системы",
                                Hours = 140
                            },
                            GroupsGuids = new []
                            {
                                new System.Guid(PS572GuidString),
                                new System.Guid(PS574GuidString)
                            },
                            ExtraInformation = "Lecture only"
                        }
                        ,
                        new TeacherLineWSScheduleDto()
                        {
                            Time = System.DateTime.Parse("01.01.2000 15:20"),
                            Auditory = "240/3б",
                            Subject = new SubjectDto()
                            {
                                Id = new System.Guid(OSGUIDSTIRNG),
                                Name = "Операционные системы",
                                Hours = 140
                            },
                            GroupsGuids = new []
                            {
                                new System.Guid(PS572GuidString),
                                new System.Guid(PS574GuidString)
                            },
                            ExtraInformation = "Lecture only"
                        }
                    }
                },
                new TeacherDayItemWSScheduleDto()
                {
                    WeekDay = System.DayOfWeek.Thursday,
                    Lines = new []
                    {
                        new TeacherLineWSScheduleDto()
                        {
                            Time = System.DateTime.Parse("01.01.2000 08:00"),
                            Auditory = "809/3б",
                            Subject = new SubjectDto()
                            {
                                Id = new System.Guid(CSHARPGUIDSTRING),
                                Name = "Программирование в среде .NET 4.0",
                                Hours = 120
                            },
                            GroupsGuids = new []
                            {
                                new System.Guid(PS572GuidString)
                            },
                            ExtraInformation = "Practice, practice, practice ..."
                        }
                    }
                },
                new TeacherDayItemWSScheduleDto()
                {
                    WeekDay = System.DayOfWeek.Friday,
                    Lines = new []
                    {
                        new TeacherLineWSScheduleDto()
                        {
                            Time = System.DateTime.Parse("01.01.2000 08:00"),
                            Auditory = "809/3б",
                            Subject = new SubjectDto()
                            {
                                Id = new System.Guid(CSHARPGUIDSTRING),
                                Name = "Программирование в среде .NET 4.0",
                                Hours = 120
                            },
                            GroupsGuids = new []
                            {
                                new System.Guid(PS574GuidString)
                            },
                            ExtraInformation = "Practice, practice, practice ..."
                        }
                    }
                },
                new TeacherDayItemWSScheduleDto()
                {
                    WeekDay = System.DayOfWeek.Saturday,
                    Lines = null
                },
                new TeacherDayItemWSScheduleDto()
                {
                    WeekDay = System.DayOfWeek.Sunday,
                    Lines = null
                }
            }

        };

        public static readonly StudentsWithGroupsDto StudentsWithGroupsDto = new StudentsWithGroupsDto()
        {
            Groups = new []
            {
                new GroupWithStudentsDto()
                {
                    Id = new System.Guid(PS572GuidString),
                    Name = "ПС-572",
                    Students = new []
                    {
                        new StudentDto()
                        {
                            Id = new System.Guid(DimaPhilimonovGuidString),
                            Name = "Dima Alex Philimonov"
                        },
                        new StudentDto()
                        {
                            Id = new System.Guid(AlexAgrutinGuidString),
                            Name = "Alexander Vlad Argutin"                            
                        }
                    }                                        
                },
                new GroupWithStudentsDto()
                {
                    Id = new System.Guid(PS574GuidString),
                    Name = "ПС-574",
                    Students = new[]
                    {
                        new StudentDto()
                        {
                            Id = new System.Guid(TimurRachmatilaevGuidString),
                            Name = "Timur H Rachmatilaev"
                        }                        
                    }
                }
            }
        };

        public static readonly ExamsListFullDataDto TimurExams = new ExamsListFullDataDto()
        {
            Student = new StudentDto()
            {
                Id = new System.Guid(TimurRachmatilaevGuidString),
                Name = "Timur H Rachmatilaev"
            },
            Exams = new []
            {
                new ExamWithSubjectAndTeacherDto()
                {
                    Auditory = "802",
                    Date = System.DateTime.Parse("05.06.2009 10:00"),
                    Id = new System.Guid(MPSGUIDSTRING),
                    Mark = Dtos.Definitions.Mark.Excellent,
                    Subject = new SubjectDto()
                    {
                        Id = new System.Guid(MPSGUIDSTRING),
                        Name = "Микропроцессорные системы",
                        Hours = 120
                    },
                    Teacher = new TeacherDto()
                    {
                        Id = new System.Guid(VinnikovGuidString),
                        Name = "Винников Борис Васильевич"
                    }
                },
                new ExamWithSubjectAndTeacherDto()
                {
                    Auditory = "801",
                    Date = System.DateTime.Parse("07.06.2009 10:00"),
                    Id = new System.Guid(OSGUIDSTIRNG),
                    Mark = Dtos.Definitions.Mark.Excellent,
                    Subject = new SubjectDto()
                    {
                        Id = new System.Guid(OSGUIDSTIRNG),
                        Name = "Операционные системы",
                        Hours = 140
                    },
                    Teacher = new TeacherDto()
                    {
                        Id = new System.Guid(KorchomkinGuidString),
                        Name = "Корчемкин Юрий Валерьевич"
                    }
                }
            }
        };
    }
}
